<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Admin_contact extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->model('model_contact', 'm_contact', TRUE);
        $this->load->model('model_city', 'm_city', TRUE);
    }
    
    function index($offset = 0, $order_column = 'datecreated', $order_type = 'DESC') {
        if(!$this->session->userdata('admin_user')){
            redirect("admin_ippi","refresh");
        }
        else{
            $list_data = $this->m_contact->get_all()->result();
            $id_prov = "";
            foreach ($list_data as $value) {
                $id_prov = $value->provinsi;
            }
            //get kota name
            $city_cond = array(
                "city_state_id"   =>  $id_prov
            );
            $data_kota= $this->m_city->get_city_by_condition($city_cond);
           
            $data = array(
                'web_title' =>  'Admin Kontak',
                'main_view' =>  'mimin/contact/add',
                'list_data' =>  $list_data,
                'list_state' =>  $this->m_city->get_all_propinsi(),
                'list_city' =>  $data_kota->result(),
            );
            $this->load->view('mimin/template/template_editor_map',$data);
        }
    }
    function detail_act(){
        $this->form_validation->set_rules('email','email','required');
        $this->form_validation->set_rules('phone','Telp','required');
        $this->form_validation->set_rules('address','Alamat','required');
        $this->form_validation->set_rules('province','province','required');
        $this->form_validation->set_rules('city','Kota','required');
        $this->form_validation->set_rules('desc','Keterangan','required');
        $this->form_validation->set_rules('lat','Lat','required');
        $this->form_validation->set_rules('long','Long','required');
        if($this->form_validation->run() == FALSE){
            $output = array(
                'status'    =>  0,
                'msg'       =>  "All fields must be filled",
            );
            echo json_encode($output);exit();
        }
        else{
            $isi_data = array(
                'email'         =>  $this->input->post('email'),
                'telp'          =>  $this->input->post('phone'),
                'alamat'        =>  $this->input->post('address'),
                'provinsi'      =>  $this->input->post('province'),
                'kota'          =>  $this->input->post('city'),
                'lat'           =>  $this->input->post('lat'),
                'long'          =>  $this->input->post('long'),
                'desc'          =>  $this->input->post('desc'),
            );
            $status_save = $this->m_contact->update_all($isi_data);
            if($status_save){
                $output = array(
                    'status'    =>  1,
                    'msg'       =>  " Contact has been updated",
                );
                echo json_encode($output);exit();
            }
        }
    }
}

/* End of file admin_member.php */
/* Location: ./application/controllers/admin_member.php */